﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AppCommon;
using SyncLib;
using Microsoft.Synchronization.Data;
using DevComponents.DotNetBar.SuperGrid;
using SyncLib.Client;

namespace SyncApplication.Dialog
{
    public partial class DetailSync : Form
    {
        DataTable tblAction = new DataTable("Action");
        DataTable tblConflictType = new DataTable("ConflictType");
        public DetailSync()
        {
            InitializeComponent();
            tblAction.Columns.Add("ID");
            tblAction.Columns.Add("Name");
            tblAction.Rows.Add(KApplyAction.Continue.ToString(), "Lưu máy trạm");
            tblAction.Rows.Add(KApplyAction.RetryWithForceWrite.ToString(), "Lưu máy chủ");
            tblAction.Rows.Add(KApplyAction.UserManual.ToString(), "Người dùng");
            //tblAction.Rows.Add(KApplyAction.Continue.ToString(), "Lưu máy trạm");

            tblConflictType.Columns.Add("ID");
            tblConflictType.Columns.Add("Name");

            //tblConflictType.Rows.Add(DbConflictType.ErrorsOccurred, "Xuất hiện lỗi");
            //tblConflictType.Rows.Add(DbConflictType.LocalCleanedupDeleteRemoteUpdate, "Máy trạm xóa tri thức, máy chủ cập nhật");
            //tblConflictType.Rows.Add(DbConflictType.LocalDeleteRemoteDelete, "Máy trạm máy chủ cùng xóa");
            //tblConflictType.Rows.Add(DbConflictType.ErrorsOccurred, "Xuất hiện lỗi");

            GridColumn col= superGridControl3.PrimaryGrid.Columns["Action"];
            GridComboBoxExEditControl com = col.RenderControl as GridComboBoxExEditControl;
            com.DisplayMember = "Name";
            com.ValueMember = "ID";
            com.DataSource = tblAction;
            //com = col.RenderControl as GridComboBoxExEditControl;
            //com.DisplayMember = "Name";
            //com.ValueMember = "ID";
            //com.DataSource = tblAction;


            historyTableSyncTableAdapter1.Connection.ConnectionString = CommonVariable.SqlConnectionString;
            historyDependencyTableAdapter1.Connection.ConnectionString = CommonVariable.SqlConnectionString;
            conflictLogsTableAdapter1.Connection.ConnectionString = CommonVariable.SqlConnectionString;
            superGridControl2.PrimaryGrid.DetachDataSource(false);
            superGridControl2.PrimaryGrid.DataSource = bindingSource2;

            superGridControl3.PrimaryGrid.DetachDataSource(false);
            superGridControl3.PrimaryGrid.DataSource = bindingSource3;
    
        }
        public void ShowMessage(String title, string message, SyncHistoryDS.HistorySyncRow row)
        {
            Text = title;
            textBoxX1.Text = message;
            this.historyTableSyncTableAdapter1.FillSyncId(syncHistoryDS1.HistoryTableSync, row.SyncHistoryId);
            this.historyDependencyTableAdapter1.FillSyncHistoryId(syncHistoryDS1.HistoryDependency, row.SyncHistoryId);
            conflictLogsTableAdapter1.FillSyncId(syncHistoryDS1.ConflictLogs, row.SyncHistoryId);
            ShowDialog();
        }
        public void ShowDetail(string title,string message, Guid sessionId)
        {
            Text = title;
            textBoxX1.Text = message;
            this.historyTableSyncTableAdapter1.FillSyncId(syncHistoryDS1.HistoryTableSync,sessionId);
            this.historyDependencyTableAdapter1.FillSyncHistoryId(syncHistoryDS1.HistoryDependency, sessionId);
            conflictLogsTableAdapter1.FillSyncId(syncHistoryDS1.ConflictLogs, sessionId);
            Show();
        }

        private void DetailSync_Load(object sender, EventArgs e)
        {

        }

        private void superGridControl3_RowDoubleClick(object sender, GridRowDoubleClickEventArgs e)
        {
          SyncHistoryDS.ConflictLogsRow conflictRow=  superGridControl3.GetCurrentRow<SyncHistoryDS.ConflictLogsRow>();
          SolveConflict frm = new SolveConflict();
          frm.ShowData(conflictRow.ConflictType, conflictRow.LocalData, conflictRow.RemoteData, conflictRow.IsSolve);
          frm.Dispose();
        }
    }
}
